package com.cms.manage.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.cms.manage.common.SysCode;
import com.cms.manage.util.RequestMapToUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(description = "内容管理")
//@ApiIgnore()
@RestController     //等同于同时加上了@Controller和@ResponseBody
@RequestMapping("/cms/article")
public class ArticleController extends BaseController{

      private static final Logger Log = LoggerFactory.getLogger(ArticleController.class);
  
	  @Autowired
	  private HttpSession session;
 
	  
	    @ApiOperation(value="激活用户", notes="激活用户")
		@ApiImplicitParams({
		@ApiImplicitParam(name = "name", value = "用户名", required = true, dataType = "String",paramType = "form"),
		@ApiImplicitParam(name = "password", value = "用户密码", required = true, dataType = "String",paramType = "form"),
		@ApiImplicitParam(name = "cdkey", value = "秘钥", required = false, dataType = "String",paramType = "form"),
		})
	    @RequestMapping(value = "/list",method = RequestMethod.GET)
	    @ResponseBody
	    public ResponseEntity<Map<String,Object>> list (HttpServletRequest request){		
			  Map<String,String> data =RequestMapToUtil.getPostByTextPlain(request);			   
	    	  Map<String, Object> result = new HashMap<String, Object>();
	    	  System.out.println("hello 文章管理！");
	    	  //result = loginService.activate(data);
	    	if(result.get("code")==SysCode.error){
	    		return ResponseEntity.status(HttpStatus.OK).body(ERROR(result.get("message"),null));
	    	 }
	    	return ResponseEntity.status(HttpStatus.OK).body(SUCCESS(result.get("message"),null)); 
	    }
	  

	  
	  
	  @ApiOperation(value="上传图片", notes="上传图片")
		@ApiImplicitParams({	
			@ApiImplicitParam(name = "user_id", value = "用户id", required = true, dataType = "String",paramType = "form"),
			@ApiImplicitParam(name = "user_name", value = "用户名", required = true, dataType = "String",paramType = "form"),
			@ApiImplicitParam(name = "type", value = "头像类型 ico:最大200*200 photo:最小200*200  ", required = true, dataType = "String",paramType = "form"),
			@ApiImplicitParam(name = "attach", value = "图片", required = true, dataType = "File",paramType = "form"),
			@ApiImplicitParam(name = "pass_key", value = "秘钥", required = true, dataType = "String",paramType = "form")				
			})
	    @RequestMapping(value = "/setUserIcon",method = RequestMethod.POST)
	    @ResponseBody
	    public ResponseEntity<Map<String,Object>> setUserIcon(HttpServletRequest request){			
			Map<String, Object> rs = null;
			 try {
			//attach 图片key	
			 rs =RequestMapToUtil.getPostByTextPlain(request,"attach");	
			} catch (Exception e) {				
				return ResponseEntity.status(HttpStatus.OK).body(SUCCESS("badFile",null)); 
			}	
			//数据集
			 Map<String,String> data =(Map<String,String>)rs.get("param");
		      //图片集
			 List<MultipartFile> fileList = (List<MultipartFile>) rs.get("fileList");
			 Map<String, String> fileRs = new HashMap<>();
			 return ResponseEntity.status(HttpStatus.OK).body(SUCCESS("","")); 
	  }

		
}
